package com.goldsprite.infinityworld.entities.components;
import com.goldsprite.gdxcore.entities.AnimatorEntity;
import com.badlogic.gdx.scenes.scene2d.ui.Touchpad;
import com.badlogic.gdx.Gdx;

public class RockerRoleController{
	private AnimatorEntity role;
	private Touchpad rocker;
	
	
	public RockerRoleController(AnimatorEntity role, Touchpad rocker){
		this.role = role;
		this.rocker = rocker;
	}
	
	
	public void update(float delta){
		inputHandle(delta);
	}
	
	public float roleMoveVel = 30;
	boolean moving;
	boolean stepTest = false;
	float stepMulti = 10;
	private void inputHandle(float delta) {
		if(stepTest && !Gdx.input.justTouched()) return;
		
		float hori = rocker.getKnobPercentX();
		float verti = rocker.getKnobPercentY();
		//摇杆被拉动时移动玩家
		if(hori!=0 || verti!=0){
			moving = true;
			float step = roleMoveVel * delta;
			//位置
			//role.getPosition().add(step * hori, step * verti);
			role.playerRect.rcoll.velocity.set(step * hori, step * verti).scl(stepTest ?stepMulti :1);
			//动画
			if(!role.getCurAnimName().equals("Walk"))role.setCurAnimation("Walk");
			//转向
			if(hori!=0) role.setFlip(hori<0, false);
		}
		else if(moving){
			moving = false;
			role.setCurAnimation("Idle");
			role.playerRect.rcoll.velocity.set(0, 0);
		}
		//LogViewerService.logDebug("[实体动画] role moving: %s, anim: %s", moving, role.getCurAnimName());
	}
	
}
